#include "gitupdaterqml.h"
#include <QMetaObject>

gitUpdaterQML::gitUpdaterQML(QObject *parent) : QObject(parent)
{
    m_git2Updater = new Git2Updater;
    m_thread = new QThread(this);
    //m_updater = new gitUpdater();

    m_git2Updater->moveToThread(m_thread);
    QMetaObject::invokeMethod(m_git2Updater, "init", Qt::QueuedConnection);
    connect(m_git2Updater, &Git2Updater::response, this, &gitUpdaterQML::response);
    connect(m_git2Updater, &Git2Updater::updateProgress, this, &gitUpdaterQML::updateProgress);
    //QMetaObject::invokeMethod(m_updater, "init", Qt::QueuedConnection);
    //connect(m_updater, &gitUpdater::response, this, &gitUpdaterQML::response);

    m_thread->start();
}

gitUpdaterQML::~gitUpdaterQML()
{
    m_thread->quit();
    m_thread->wait();
    //delete m_updater;
    delete m_git2Updater;
}

void gitUpdaterQML::getCurrentVersion()
{
    QMetaObject::invokeMethod(m_git2Updater, "getLatestVersionInfo", Qt::QueuedConnection);
}

void gitUpdaterQML::getLatestVersion()
{
    QMetaObject::invokeMethod(m_git2Updater, "getLatestVersionInfo", Qt::QueuedConnection);
    //QMetaObject::invokeMethod(m_updater, "getLatestVersion", Qt::QueuedConnection);
}

void gitUpdaterQML::startUpdate()
{
    QMetaObject::invokeMethod(m_git2Updater, "startUpdate", Qt::QueuedConnection);
    //QMetaObject::invokeMethod(m_updater, "startUpdate", Qt::QueuedConnection);
}
